#include<iostream>
using namespace std;
#include<time.h>
enum State {R,C};
struct PCB{
    char name;
    int startTime;
    int runTime;
    State processState;
    PCB* next;
};

PCB* create_data(){
    PCB* start = new PCB();
    PCB* res = start;
    PCB* pre;
    unsigned int seed = 10;
    srand(seed);
    for(int i=0;i<10;i++){
        start->name = 'a' + i;
        start->startTime = i;
        start->runTime = rand()%10+1;
        start->processState = State::R;
        start->next = new PCB();
        pre = start;
        start = start->next;
    }
    pre->next = NULL;
    return res;
}
class solutions{
private: 
    PCB* head;
    PCB* tail;
public:
    solutions(PCB* p){
        head = p;
        PCB* cur = p;
        while(cur->next){
            cur = cur->next;    
        }
        tail = cur;
        tail->next = head;
    }
    // void run();
    char run(){
        if(head==NULL)return '\0';
        char res = head->name;
        if(head->runTime==1){
            tail->next = head->next;
            head = head->next;
            if(head==tail){
                head=tail=NULL;
            }
        }else{
            head->runTime--;
            tail = tail->next;
            head = head->next;
        }
        return res;
    }
    void add(PCB* ptr){
        tail->next = ptr;
        ptr->next = head;
        tail = ptr;
    }
};

int main(){
    PCB* data = create_data();
    PCB* start = data;
    while(start){
        printf("the name is: %c, the runTime is: %d\n",start->name,start->runTime);
        start = start->next;
    }
    // return 0;
    solutions s(data);
    char c = s.run();
    while(c!='\0'){
        printf("%c ",c);
        c = s.run();
    }
    printf("\n");
}